import ajax from '@/service/ajax'
import { reactive, ref, toRefs, getCurrentInstance } from 'vue'


export default function hookFunction($toast, $alert) {

    let subAllAccountList = reactive([]);

    // 判断是否开启商城版公用方法
    function checkOpenMail(opts) {
        ajax.getOpenMallStatus().then(rs => {
            if (rs.code == 0) {
                if (rs.data.openStatus == 1) {
                    opts.successCB()
                } else if (rs.data.openStatus == 0) {
                    openMail(opts.openMailText, '去开通', opts.openMailLink)
                } else if (rs.data.openStatus == 2) {
                    openMail(opts.overdueText, '去续费', opts.overdueLink)
                }
            } else {
                $toast(rs?.status?.message)
            }
        }).catch(err => {
            $toast(err?.status?.message)
        })
    };

    // 开通商城版弹窗
    function openMail(text1, text2, link) {
        $alert(text1, '', {
            confirmButtonText: text2,
            cancelButtonText: '取消',
            showClose: false,
            showCancelButton: true,
            callback: action => {
                if (action == 'confirm') {
                    parent.postMessage({
                        url: link//每个功能跳转开通商城版都会有一个wfr标识,联系产品同学获取.
                    }, '*')
                }
            }
        });
    };

    return {
        getSublist,
        checkOpenMail,
        subAllAccountList
    }
}
